package test_new;

public class BinarySearch {
	
	
	public static int doBinarySearch(int[] array, int searchElement) {
		int firstElementOfSegment = 0;
		int lastElementOfSegment = array.length-1;
		while (firstElementOfSegment <= lastElementOfSegment) {
			int middleOfSegment = (lastElementOfSegment + firstElementOfSegment)/2;
			if (array[middleOfSegment] == searchElement) {
				return middleOfSegment;
			} else if (array[middleOfSegment] < searchElement) {
				firstElementOfSegment = middleOfSegment + 1;
			} else lastElementOfSegment = middleOfSegment - 1;
		}
		return -1;
		
	}

}
